package com.cxs.service.impl;

import com.cxs.mapper.AnswersMapper;
import com.cxs.mapper.QuestionsMapper;
import com.cxs.model.Answers;
import com.cxs.model.Questions;
import com.cxs.service.AnswersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/*
 * @Author:cxs
 * @Date:2021/10/3  17:27
 * @Version 1.0
 * @Motto:放下杂念,只为迎接明天更好的自己
 * */
@Service
public class AnswersServiceImpl implements AnswersService {

    @Autowired
    private AnswersMapper answersMapper;

    @Autowired
    private QuestionsMapper questionsMapper;

    @Override
    public int add(Answers answers) {
        Questions questions = questionsMapper.selectByPrimaryKey(answers.getQid());
        Questions newQuest = new Questions();
        newQuest.setId(questions.getId());
        newQuest.setAnswerCount(questions.getAnswerCount() + 1);
        questionsMapper.updateByPrimaryKeySelective(newQuest);
        return answersMapper.insertSelective(answers);
    }
}
